package com.leapp.sk.ui.activity.classs

import android.Manifest
import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.view.View
import com.example.mvp.activity.BaseActivityMVP
import com.example.mvp.binder.BaseDataBinder
import com.example.util.StatusBarColorUtil
import com.leapp.sk.R
import com.leapp.sk.binder.BaseBinder
import com.leapp.sk.viewdelegate.classs.HeadmasterDetialDelegate
import android.content.pm.PackageManager
import android.graphics.Color
import android.net.Uri
import android.support.v4.app.ActivityCompat
import com.example.baselibrary.util.SKPermissionUtils
import com.example.mvp.bean.ClassMemberInfoEntity
import com.githang.statusbar.StatusBarCompat
import com.leapp.sk.app.SKApplication
import com.leapp.sk.ui.activity.im.SingleChatActivity
import com.example.util.finallist.MESSAGE_LIST_ID
import com.example.util.finallist.TECHER_NICK
import com.example.util.finallist.THEACHER_DATA
/**
 * 班主任资料
 * @author  chaohaipeng  on 2018/8/1.
 */
class HeadmasterDetialActivity : BaseActivityMVP<HeadmasterDetialDelegate>() {
    /**
     * 老师数据
     */
    var techerData: ClassMemberInfoEntity?=null
    override fun initView(p0: Bundle?) {
        StatusBarColorUtil.setHideNavigion(this)
        StatusBarCompat.setStatusBarColor(this,Color.TRANSPARENT , false)
        viewDelegate.initData()

        if (techerData!=null){
            viewDelegate.setData(this,techerData)
        }
    }
    override fun initDate() {
        try {
            techerData= intent?.getSerializableExtra(THEACHER_DATA) as ClassMemberInfoEntity?
        }catch (e:Exception){
        }
    }

    override fun bindEvenListener() {
        viewDelegate.setOnClickListener(View.OnClickListener {
            finish()
        }, R.id.iv_ahmd_back)
        viewDelegate.setOnClickListener(View.OnClickListener {
            if (techerData!=null){
                callPhone(techerData?.phone)
            }

        }, R.id.tv_ahmd_play_pohone)
        viewDelegate.setOnClickListener(View.OnClickListener {
            if (techerData!=null){
            val intent: Intent = Intent(this, SingleChatActivity::class.java)
            intent.putExtra(MESSAGE_LIST_ID, techerData!!.id)
            intent.putExtra(TECHER_NICK, techerData?.nickName)
            startActivity(intent)
            }
        }, R.id.tv_ahmd_send_message)

    }

    override fun getDelegateClass(): Class<HeadmasterDetialDelegate> {
        return HeadmasterDetialDelegate::class.java
    }

    override fun getDataBinder(): BaseDataBinder<*, *> {
        return BaseBinder()
    }


    @SuppressLint("MissingPermission")
            /**
             * 拨打电话（直接拨打电话）
             * @param phoneNum 电话号码
             */
    fun callPhone(phoneNum: String?) {
        //用intent启动拨打电话
        if (SKPermissionUtils.getInstance().setCallPhonePermission(this, SKApplication.getInstance())) {
            val intent = Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNum))
            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                return
            }
            startActivity(intent)
        }
    }


}